Skip to content

perf: Allow to pass a selector to useWindowDimensions(state => state.fontScale) to avoid unnecessary re-renders - #57185

Closed
retyui wants to merge 1 commit into
react:mainfrom
retyui:feat/retyui/useWindowDimensions-with-selector
Closed

perf: Allow to pass a selector to useWindowDimensions(state => state.fontScale) to avoid unnecessary re-renders#57185
retyui wants to merge 1 commit into
react:mainfrom
retyui:feat/retyui/useWindowDimensions-with-selector

Conversation

@retyui

@retyui retyui commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary:

Performance issue was shown on App.js 2026 Conf: https://www.youtube.com/live/4H8iRPN0Q2M?si=pykgDXJcbvi7_OIC&t=8704 by @jmeistrich

// but now with this PR devs can pass a selector 
// to subscribe to `fontScale` changes only 
const fontScale = useWindowDimensions(state => state.fontScale)
Screenshot 2026-05-28 at 18 12 22

Changelog:

[GENERAL] [ADDED] - Allow to pass a selector to useWindowDimensions(state => state.fontScale) to avoid unnecessary re-renders

Test Plan:

I did my best to cover all testcases:

yarn test packages/react-native/Libraries/Utilities/__tests__/useWindowDimensions-test.js

….fontScale)` to avoid unnecessary re-renders
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 12, 2026
@github-actions

Copy link
Copy Markdown

Warning

JavaScript API change detected

This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API.

  • Please include a clear changelog message.
  • This change will be subject to additional review.

This change was flagged as: POTENTIALLY_BREAKING

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jun 12, 2026
@retyui

retyui commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Hey @cortinico ! Do you know somebody in Meta who can review this PR ?

@cortinico

Copy link
Copy Markdown
Contributor

Hey @cortinico ! Do you know somebody in Meta who can review this PR ?

Potentially @javache

@cortinico
cortinico requested a review from javache June 23, 2026 09:31
@retyui

retyui commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@javache Could you please review this PR?

@javache

javache commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

I'm hesitant to addd this as a core API since React hasn't moved ahead with context selectors (react/react#20646) either.

My assumption is that when using React compiler, this type of memoization should be equivalent, and React should be able to bail out from rendering fairly quickly. Is that not what you're observing?

Alternatively, you could build this type of hook yourself using the existing public React Native API, no?

@javache javache closed this Jun 29, 2026
@retyui

retyui commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Callstack Partner: Callstack Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants